# Build recipe for libaio.
#
# Copyright (c) 2018-2020 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=libaio
version=0.3.112
release=3

# Define a category for the output of the package name
pkgcategory=libs

tarname=${program}_${version}.orig.tar.xz

# Remote source(s)
fetch=https://ftp.debian.org/debian/pool/main/liba/libaio/$tarname

description="
Kernel Asynchronous I/O (AIO) support for GNU/Linux.

AIO enables even a single application thread to overlap I/O operations
with other processing, by providing an interface for submitting one or
more I/O requests in one system call (io_submit()) without waiting for
completion, and a separate interface (io_getevents()) to reap
completed I/O operations associated with a given completion group.
"

homepage=https://lse.sourceforge.net/io/aio.html
license=LGPLv2+

# Source documentation
docs="COPYING ChangeLog TODO"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    # Apply patches from Debian, upstream to refresh this source
    while read -r line
    do
        case $line in
        *.patch)
            patch -Np1 -i "${worktree}/patches/libaio/${line}"
            ;;
        esac
    done < "${worktree}/patches/libaio/series"

    make CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS -fno-stack-protector" LDFLAGS="$QILDFLAGS" \
         prefix="${destdir}/usr" \
         libdir="${destdir}/usr/lib${libSuffix}" \
         install

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

